package com.maimao.model.goods;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author MaoLin Wang
 * @date 2020/11/27 11:16 下午
 */
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@TableName("mm_category")
public class Category implements Serializable {

    private static final long serialVersionUID = 4451019575966415562L;

    @TableId(type = IdType.AUTO)
    private Integer id;

    @NotBlank(message = "分类名不能为空")
    @TableField("`name`")
    private String name;


    private Integer level;

    @NotNull(message = "请选择父级分类")
    @Min(value = 0, message = "父级分类非法")
    private Integer pid;

    /**
     * 非数据库字段
     */
    @TableField(exist = false)
    private String pname;

    @TableField("`order`")
    @NotNull(message = "排序不能为空")
    private Integer order;

    @NotNull(message = "使用状态不能为空")
    @TableField("`status`")
    private Integer status;


    private String picture;

    @TableField("mobile_name")
    private String mobileName;

    private String pinyin;

    private String head;

    @TableField("create_time")
    private LocalDateTime createTime;

    @TableField("update_time")
    private LocalDateTime updateTime;

    @TableField(exist = false)
    private List<Category> children;

    /**
     * 前端回显需要的父级所有层级的id，非直接父级
     */
    @TableField(exist = false)
    private List<Integer> pidTemp;

    @Override
    public String toString() {
        return "Category{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", level=" + level +
                ", pid=" + pid +
                ", pname='" + pname + '\'' +
                ", order=" + order +
                ", status=" + status +
                ", picture='" + picture + '\'' +
                ", mobileName='" + mobileName + '\'' +
                ", pinyin='" + pinyin + '\'' +
                ", head='" + head + '\'' +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                ", children=" + children +
                ", pidTemp=" + pidTemp +
                '}';
    }
}
